import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.*;

public class SessionChk extends HttpServlet
{
    private HttpServletRequest request=null;
	private HttpServletResponse response=null;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
    {
		 this.request=request;
		 this.response=response;
         processRequest(request,response);
    }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
  {
		 this.request=request;
		 this.response=response;
         processRequest(request,response);
  }
   public void processRequest(HttpServletRequest request, HttpServletResponse response)
  {
    try
     {      
         String userId=getSession("userSession");
		 if(isAuthenticate(userId))
		 	response.sendRedirect("Inbox.html");
		 else
			response.sendRedirect("LoginPage.html");
       	
     }catch(Exception e)
      {
         //out.println(e.toString());
      }
  }

	private boolean isAuthenticate(String uid)
	{
		if(uid.equals("jabu"))
			return true;
		else
			return false;
	}
private String getSession(String sessionName)
	{
       HttpSession session = request.getSession(true);
	   //session.getAttribute("SessionName");
	   return (String)session.getAttribute(sessionName);
	 }
}
